import java.util.ArrayList;

public class Agent implements Comparable<Agent>{

	ArrayList<Card> cards = new ArrayList<Card>();
	String name;
	Table table;
	private boolean folded = false;
	int money = 1000;
	public static int BASE_MONEY = 1000;

	public Agent()
	{

	}

	public Agent setFold(boolean b){folded = b; return this;}
	public boolean getFold(){return folded;}

	public Agent initialize(Table t)
	{
		table = t;
		return this;
	}

	/**
	 * 
	 * @return the hand the agent has, including the shared cards
	 */
	public ArrayList<Card> getFullCards()
	{
		ArrayList<Card> fullCards = new ArrayList<Card>();
		fullCards.addAll(cards);
		fullCards.addAll(table.visibleCards);
		return fullCards;

	}

	public int compareTo(Agent a)
	{
		if (getFold())
			return -1;
		
		return Hand.getBestHand(getFullCards()).compareTo(Hand.getBestHand(a.getFullCards()));
	}

	public Agent setName(String s)
	{
		name = s;
		return this;
	}

	public void newHand()
	{
		cards = new ArrayList<Card>();
	}

	public void dealCard(Card card)
	{
		cards.add(card);
	}

	public Action takeTurn()
	{
		evaluateProbabilities();
		if (Simulator.DEBUG)
		printCards();
		return Action.callAction();
	}

	public void printCards()
	{
		if (!Simulator.DEBUG)
			return;
		System.out.print("Cards:");
		for (Card card : cards)
		{
			System.out.print(" ");
			System.out.print(card.toStringShort());
		}
		System.out.println();

	}

	public void printMoney()
	{
		System.out.println("Money: " + money);
		System.out.println("Current bet: " + table.bets.get(this));
	}

	public void evaluateProbabilities(){}

	public String toString()
	{
		return "Agent " + name;
	}

	public Agent addMoney(int val)
	{
		money += val;
		return this;
	}

}
